package com.etc;

import java.awt.image.BufferedImage;

/**
 * 英雄机： 是飞行物
 */
public class Hero extends FlyingObject {

    // 生命值
    private int life;
    //火力值
    private int doubleFire;
    //图片
    private BufferedImage[] images;
    //图片切换频率
    private int index;

    public Hero() {
        image = AircraftwarGame.hero0;
        width = image.getWidth();
        height = image.getHeight();
        x = 150;
        y = 400;
        life = 3;
        doubleFire = 0;
        images = new BufferedImage[]{AircraftwarGame.hero0, AircraftwarGame.hero1};
        index = 0;
    }


    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public int getDoubleFire() {
        return doubleFire;
    }

    public void setDoubleFire(int doubleFire) {
        this.doubleFire = doubleFire;
    }

    public BufferedImage[] getImages() {
        return images;
    }

    public void setImages(BufferedImage[] images) {
        this.images = images;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public void step() {
        index++;
        int a = index / 10;
        int b = a % 2;
        image = images[b];

        /**
         * a % b =  a - (int)(a/b)*b     % 取余    求模
         *
         * 1 a = 0  b = 0
         * 2 a = 0  b = 0
         * ....
         * 10  a = 1  b = 1
         * 11  a = 1  b = 1
         *
         *
         *
         */

    }

    @Override
    public boolean outBounds() {
        return false;
    }

    /**
     * 发射子弹
     *
     * @return
     */
    public Bullet[] shoot() {
        // 1/4 英雄机的宽度
        int xStop = this.width / 4;
        int yStop = 20;

        if (doubleFire > 0) {
            Bullet[] bullets = new Bullet[2];
            bullets[0] = new Bullet(this.x + xStop, this.y - yStop);
            bullets[1] = new Bullet(this.x + xStop * 3, this.y - yStop);
            // 发射子弹要给子弹的数量减2
            doubleFire -= 2;
            return bullets;
        } else {
            Bullet[] bullets = new Bullet[1];
            bullets[0] = new Bullet(this.x + xStop * 2, this.y - yStop);
            return bullets;
        }

    }


    /**
     * 游戏机移动
     * @param x
     * @param y
     */
    public void moveTo(int x, int y) {
        this.x = x - this.width / 2;
        this.y = y -  this.height / 2;
    }

}
